﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using Semantics.Base;
using Semantics.Remoting;

namespace NaturalWiki.Backend
{
    public class RemotableMentorProxy
    {
        RemotableMentor Mentor;
        public RemotableMentorProxy(RemotableMentor mentor)
        {
            this.Mentor = mentor;
        }
        public List<Semantics.Silverlight.Category> GetSubCategories(int nodeid)
        {
            ArrayList categories = this.Mentor.GetSubCategories(nodeid);
            return ToSilverCategories(categories);
        }
        List<Semantics.Silverlight.Category> ToSilverCategories(ArrayList categories)
        {

            List<Semantics.Silverlight.Category> silvercates = new List<Semantics.Silverlight.Category>();
            for (int i = 0; i < categories.Count; i++)
            {
                silvercates.Add(this.ToSilverCategory((Category)categories[i]));
            }
            return silvercates;
        }


        public Semantics.Silverlight.Category ToSilverCategory(Category cate)
        {
            Semantics.Silverlight.Category silvercate = new Semantics.Silverlight.Category();
            silvercate.NodeId = cate.Node.Id;
            if(cate.Parent!=null)
                silvercate.ParentId = cate.Parent.Id;
            silvercate.Value = cate.Node.Label;
            silvercate.Example = cate.Example;
            return silvercate;
        }
        public int CreateWord(string word, int categorynodeid)
        {
            int result = this.Mentor.CreateNode(word, categorynodeid);
            return result;
        }
        public List<Semantics.Silverlight.Category> SearchCategories(string word)
        {
            ArrayList categories = this.Mentor.SearchCategories(word);
            return ToSilverCategories(categories);
        }
        public List<Semantics.Silverlight.Category> GetCategroyHierarchy(int nodeid)
        {
            ArrayList categories = this.Mentor.GetCategroyHierarchy(nodeid);
            return ToSilverCategories(categories);
        }
    }
}